from typing import List, Optional, Dict, Any
from pydantic import BaseModel, Field
from datetime import datetime
import json

class ChartModel(BaseModel):
    """图表模型"""
    id: str = Field(description="图表唯一ID")
    title: str = Field(description="图表标题")
    description: Optional[str] = Field(default=None, description="图表描述")
    question: str = Field(description="原始问题")
    sql: str = Field(description="SQL查询语句")
    chart_type: str = Field(description="图表类型：plotly, table等")
    chart_config: Dict[str, Any] = Field(description="图表配置JSON")
    data_config: Dict[str, Any] = Field(description="数据配置JSON")
    created_at: datetime = Field(default_factory=datetime.now)
    updated_at: datetime = Field(default_factory=datetime.now)
    tags: List[str] = Field(default=[], description="标签")

class DashboardModel(BaseModel):
    """Dashboard模型"""
    id: str = Field(description="Dashboard唯一ID")
    name: str = Field(description="Dashboard名称")
    description: Optional[str] = Field(default=None, description="Dashboard描述")
    layout_config: Dict[str, Any] = Field(description="布局配置JSON")
    created_at: datetime = Field(default_factory=datetime.now)
    updated_at: datetime = Field(default_factory=datetime.now)
    is_public: bool = Field(default=False, description="是否公开")

class DashboardChartModel(BaseModel):
    """Dashboard图表关联模型"""
    dashboard_id: str = Field(description="Dashboard ID")
    chart_id: str = Field(description="图表ID")
    position: Dict[str, Any] = Field(description="位置配置：{x, y, width, height}")
    order: int = Field(description="显示顺序")